package io.lckgroup.modules.lck.controller.wxmp;

import com.alibaba.fastjson.JSONObject;
import io.lckgroup.modules.lck.service.WeixinCallbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.*;

/**
 * @author huangrui
 */
@RestController
@RequestMapping("/mp/callback")
public class CallBackController {
    @Autowired
    private WeixinCallbackService weixinCallbackService;

    /**
     * 功能描述: <br>
     * 〈〉支付后的银行回调，bug问题是，一个订单会多次回调，直接判断当前回调的订单号的支付状态，
     * 若已支付，则直接忽略不打印，反之则打印
     *
     * @Param: [map, request]
     * @Return: java.lang.String
     * @Author: 13980
     * @Date: 2020/3/13 11:35
     */
    @PostMapping("/callback")
    public Object huidiao(@RequestBody Map<String, Object> map, HttpServletRequest request) {
        System.out.println("-----------------------------------支付回调----------------------------------");
        boolean tradeNo = weixinCallbackService.weixinIsPay(map.get("outTradeNo").toString());
        if (tradeNo) {
            weixinCallbackService.weixinChangeOrderState(map);
        }
        Map map1 = new HashMap<String, Object>();
        map1.put("result", "SUCCESS");
        JSONObject jsonObject = JSONObject.parseObject("{\"result\":\"SUCCESS\"}");
        System.out.println("返回的json对象："+jsonObject);
        return jsonObject;
    }
}
